home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util1 / ssmn012c.lha / Sysmon / src / SysLog.c < prev    next >
C/C++ Source or Header  |  1995-11-20  |  3KB  |  107 lines

  1. /*
  2. **    $RCSfile: SysLog.c,v $
  3. **    $Filename: SysLog.c $
  4. **    $Revision: 0.1 $
  5. **    $Date: 1995/02/18 17:33:51 $
  6. **
  7. **    sysmon.library support command SysLog (version 0.3) 
  8. **    
  9. **    (C) Copyright 1995 by Etienne Vogt
  10. */
  11.  
  12. #include <exec/alerts.h>
  13. #include <dos/dos.h>
  14. #include <workbench/startup.h>
  15. #define __USE_SYSBASE
  16. #include <proto/exec.h>
  17. #include <proto/dos.h>
  18. #include <string.h>
  19. #include <stdlib.h>
  20. #include "sysmon.h"
  21. #include "sysmon_protos.h"
  22. #include "sysmon_pragmas.h"
  23.  
  24. struct ExecBase *SysBase;
  25. struct DosLibrary *DOSBase;
  26. struct Library *SysmonBase;
  27. static struct WBStartup *wbmsg;
  28. static struct RDArgs *myrda;
  29.  
  30. ULONG __saveds main(void);
  31. static void cleanexit(ULONG rc);
  32. static BOOL SysLog(ULONG priority, APTR format, ...);
  33.  
  34. static UBYTE version[] = "$VER: SysLog 0.3 (8.10.95)";
  35. static UBYTE template[] = "MESSAGE/A,LEVEL/K/N,NOHEAD/S,NOWIN/S,NOFILE/S";
  36.  
  37. #define OPT_MESSAGE    0
  38. #define    OPT_LEVEL    1
  39. #define OPT_NOHEAD    2
  40. #define    OPT_NOWIN    3
  41. #define    OPT_NOFILE    4
  42. #define OPTMAX        5
  43.  
  44. ULONG __saveds main(void)    /* No startup code */
  45. {
  46.   struct Process *myproc;
  47.   LONG opts[OPTMAX];
  48.   ULONG level;
  49.  
  50.   SysBase = *(struct ExecBase **)4;
  51.   DOSBase = NULL;
  52.   SysmonBase = NULL;
  53.   wbmsg = NULL;
  54.   myrda = NULL;
  55.  
  56.   myproc = (struct Process *)FindTask(NULL);
  57.   if ((DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",36)) == NULL)
  58.   { Alert(AT_Recovery|AG_OpenLib|AO_DOSLib);
  59.     return 100;
  60.   }
  61.  
  62.   if (!(myproc->pr_CLI))        /* If started from WB, exit cleanly */
  63.   { WaitPort(&(myproc->pr_MsgPort));
  64.     wbmsg = (struct WBStartup *)GetMsg(&(myproc->pr_MsgPort));
  65.     cleanexit(20);
  66.   }
  67.   else
  68.   { memset((char *)opts, 0, sizeof(opts));
  69.     if ((SysmonBase = OpenLibrary("sysmon.library",0)) == NULL)
  70.     { Printf("SysLog : Couldn't open sysmon.library\n");
  71.       cleanexit(20);
  72.     }
  73.     if ((myrda = ReadArgs(template, opts, NULL)) == NULL)
  74.     { PrintFault(IoErr(),NULL);
  75.       cleanexit(20);
  76.     }
  77.     if (opts[OPT_LEVEL]) level = *((ULONG *)opts[OPT_LEVEL]);
  78.     else level = LOG_DEBUG;
  79.  
  80.     if (opts[OPT_NOHEAD]) level |= LOG_NOHEAD;
  81.     if (opts[OPT_NOFILE]) level |= LOG_NOFILE;
  82.     if (opts[OPT_NOWIN]) level |= LOG_NOWIN;
  83.  
  84.     if (!SysLog(level, "%s\n", (APTR)opts[OPT_MESSAGE]))
  85.     { Printf("SysLog : Error sending message\n>%s\n",(STRPTR)opts[OPT_MESSAGE]);
  86.       cleanexit(10);
  87.     }
  88.   }
  89.   cleanexit(0);
  90. }
  91.  
  92. static void cleanexit(ULONG rc)
  93. {
  94.   if (myrda) FreeArgs(myrda);
  95.   if (DOSBase) CloseLibrary((struct Library *)DOSBase);
  96.   if (SysmonBase) CloseLibrary(SysmonBase);
  97.   if (wbmsg)
  98.   { Forbid();
  99.     ReplyMsg((struct Message *)wbmsg);
  100.   }
  101.   Exit(rc);
  102. }
  103.  
  104. static BOOL SysLog(ULONG priority, APTR format, ...)
  105. { return smVSysLog(priority, format, &format + 1);
  106. }
  107.